package com.company.card_service.api;


import com.company.card_service.model.ForwardView;
import com.company.card_service.model.Message;
import com.company.card_service.model.Reply;
import com.company.card_service.service.ReplyService;
import com.company.card_service.serviceImpl.MessageServiceImpl;
import com.company.card_service.vo.ReplyVo;
import com.company.card_service.vo.Result;
import com.company.card_service.vo.ResultCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "提供留言管理页面中的相关接口", tags = "留言管理管理")
@RestController
@RequestMapping("api/company/message")
public class ApiMessageController {
    @Autowired
    MessageServiceImpl messageService;

    @Autowired
    ReplyService replyService;

    @PostMapping("/addMessage")
    @ApiOperation("增加留言数据")
    public Result addMessage(@RequestBody Message  message){
        Boolean aBoolean = messageService.saveAll(message);
            return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),aBoolean);
    }



    @ApiOperation(value = "留言管理页面中员工回复客户留言接口")
    @PostMapping("/reply/{messageId}")
    public Result addReplyMessage(@RequestBody Reply reply, @PathVariable Integer messageId){
        Result result = replyService.addReply(reply,messageId);
        return result;
    }

    @ApiOperation(value = "留言管理页面中通过员工id查询留言接口(分页)")
    @GetMapping("/query/{eid}/{pageNum}/{limit}")
    public Result selectMessageById(@PathVariable("eid") Integer eid,@PathVariable("pageNum") Integer pageNum,@PathVariable("limit")Integer limit){
        Result result = messageService.getMessageById(eid,pageNum,limit);
        return result;
    }

    @ApiOperation(value = "留言管理页面中统计留言接口")
    @GetMapping("/count/{eid}")
    public Result selectMessageCountById(@PathVariable Integer eid){
        Result result = messageService.getMessageCountById(eid);
        return result;
    }
    @ApiOperation(value = "留言管理页面中通过员工id查询公开留言接口")
    @GetMapping("/queryPublic/{eid}/{pageNum}/{limit}")
    public Result selectPublicMessageById(@PathVariable("eid") Integer eid,@PathVariable("pageNum") Integer pageNum,@PathVariable("limit")Integer limit){
        Result result = messageService.getPublicMessageVoById(eid,pageNum,limit);
        return result;
    }
    @ApiOperation(value = "留言管理页面中通过员工id查询不公开留言接口")
    @GetMapping("/queryNoPublic/{eid}/{pageNum}/{limit}")
    public Result selectNoPublicMessageById(@PathVariable("eid") Integer eid,@PathVariable("pageNum") Integer pageNum,@PathVariable("limit")Integer limit){
        Result result = messageService.getNoPublicMessageVoById(eid,pageNum,limit);
        return result;
    }
    @ApiOperation(value = "留言管理页面中通过员工id查询待回复留言接口(0是待回复)")
    @GetMapping("/queryNoReply/{eid}/{pageNum}/{limit}")
    public Result selectNoReplyMessageById(@PathVariable("eid") Integer eid,@PathVariable("pageNum") Integer pageNum,@PathVariable("limit")Integer limit){
        Result result = messageService.getNoReplyMessageVoById(eid,pageNum,limit);
        return result;
    }
    @ApiOperation(value = "留言管理页面中通过员工id查询已回复留言接口(1是已回复)")
    @GetMapping("/queryReply/{eid}/{pageNum}/{limit}")
    public Result selectReplyMessageById(@PathVariable("eid") Integer eid,@PathVariable("pageNum") Integer pageNum,@PathVariable("limit")Integer limit){
        Result result = messageService.getReplyMessageVoById(eid,pageNum,limit);
        return result;
    }

    @ApiOperation(value = "留言管理页面中删除留言接口")
    @GetMapping("/updateReply")
    public Result updateReply(@RequestBody ReplyVo replyVo ){
        replyService.updateReplyById(replyVo);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(),ResultCodeEnum.SUCCESS.getMessage());
    }

    @ApiOperation(value = "留言管理页面中删除留言接口")
    @GetMapping("/deleteMessage/{id}")
    public Result deleteMessageById(@PathVariable Integer id){
        messageService.removeMessageById(id);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(),ResultCodeEnum.SUCCESS.getMessage());
    }

}
